import configparser

import tkinter as tk
from tkinter import *
from tkinter import ttk

config = configparser.ConfigParser()
config.read('../Config/config.ini')

project_path = config.get('ProjectInfo', 'project_path')
project_name = config.get('ProjectInfo', 'project_name')

def get_version():
    with open(project_path + '/' + project_name + '/Config/Version.ini', 'r') as f:
        return f.read().strip()

def openUpdateVersion():
    from Apps.Functions.GenerateVersion import UpdateVersion

    root = Tk()
    root.title("Unreal Project Developer Tools ( UPDT ) - Update version")
    root.geometry("300x400")
    root.wm_minsize(300,300)
    root.wm_maxsize(300,500)

    frame = Frame(root, padx=10, pady=10)
    frame.pack(expand=True)
    
    CurrentVersion_label = ttk.Label(frame, text=f"Current version: {get_version()}")
    CurrentVersion_label.grid(row=1, column=1)

    ButtonsFrame = ttk.Frame(frame)
    ButtonsFrame.grid(row=2, column=1)

    UpdateVersion_Major_Button = ttk.Button(ButtonsFrame, text="Major", command=lambda:UpdateVersion(0))
    CurrentVersion_label = ttk.Label(frame, text=f"Current version: {get_version()}")
    UpdateVersion_Major_Button.grid(row=1, column=1)

    UpdateVersion_Middle_Button = ttk.Button(ButtonsFrame, text="Middle", command=lambda:UpdateVersion(1))
    CurrentVersion_label = ttk.Label(frame, text=f"Current version: {get_version()}")
    UpdateVersion_Middle_Button.grid(row=1, column=2)

    UpdateVersion_Minor_Button = ttk.Button(ButtonsFrame, text="Minor", command=lambda:UpdateVersion(2))
    CurrentVersion_label = ttk.Label(frame, text=f"Current version: {get_version()}")
    UpdateVersion_Minor_Button.grid(row=1, column=3)